package com.tanhua.dubbo.api.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tanhua.domain.db.User;
import com.tanhua.dubbo.api.UserApi;
import com.tanhua.dubbo.mapper.UserMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * 用户服务接口实现
 */
@Service
public class UserApiImpl implements UserApi {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public User findByMobile(String mobile) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        // 参数1-字段名，参数2-参数值
        wrapper.eq("mobile", mobile);
        User user = userMapper.selectOne(wrapper);
        return user;
    }

    public void update(User user) {
        userMapper.updateById(user);
    }

    @Override
    public List<User> findAll() {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.le("id", 80);

        List<User> userList = userMapper.selectList(queryWrapper);
        return userList;
    }
}
